package cn.tedu.backend.portal.service.imp;

import cn.tedu.backend.portal.mapper.UserMapper;
import cn.tedu.backend.portal.model.User;
import cn.tedu.backend.portal.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class UserServiceImp extends ServiceImpl<UserMapper, User> implements IUserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public PageInfo<User> getUsers(Integer pageNum,Integer pageSize) {
        //PageHelper.startPage能够使紧随其后执行的一次sql查询
        //自动生成指定的分页limit语句
        //方法的第一个参数是页码,从1开始,第二个参数是每页条数
        PageHelper.startPage(pageNum,pageSize);
        //可以添加在serverimp的查询并返回的语句前  ↑↑↑↑↑

        List<User> list = userMapper.selectAll();
//        log.debug("查询到用户的数量为:{}",list.size());

        //new PageInfo<>(list)表示实例化一个PageInfo对象
        //list是构造方法的参数
        //PageInfo内部实例化时会自动赋值分页信息
        //list参数会赋值到PageInfo list属性中
        return new PageInfo<>(list);
    }

    public int deleteByUserId(String userId){
        int del = userMapper.deleteByUserId(userId);
        return del;
    }

    @Override
    public String selectNicknameByUserId(String userId) {
        String adminUser = userMapper.selectNicknameByUserId(userId);
        System.out.println(adminUser);
        return adminUser;
    }

//    @Override
//    public String selectNicknameByUserId() {
//        String adminUser = userMapper.selectNicknameByUserId();
//        System.out.println(adminUser);
//        return adminUser;
//    }

    public int selectCount(){
        return userMapper.selectCount();
    }

    public int selectVipCount(){
        return userMapper.selectVipCount();
    }

    @Override
    public int selectNormalCount() {
        return userMapper.selectNormalCount();
    }


}
